package top.tangyh.lamp.care.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.tangyh.basic.exception.BizException;
import top.tangyh.lamp.care.entity.BGenItem;
import top.tangyh.lamp.care.mapper.BGenItemDetailMapper;
import top.tangyh.lamp.care.mapper.BGenItemMapper;
import top.tangyh.lamp.care.service.BGenItemDetailService;
import top.tangyh.basic.base.service.impl.SuperServiceImpl;
import top.tangyh.lamp.care.manager.BGenItemDetailManager;
import top.tangyh.lamp.care.entity.BGenItemDetail;
import top.tangyh.lamp.care.vo.query.GenItemDetailQueryParam;
import top.tangyh.lamp.care.vo.result.GenItemDetailMapDto;
import top.tangyh.lamp.care.vo.save.BGenItemDetailSaveVO;
import top.tangyh.lamp.care.vo.save.GenItemDetailQuickSaveParam;
import top.tangyh.lamp.care.vo.update.BGenItemDetailUpdateVO;
import top.tangyh.lamp.care.vo.result.BGenItemDetailResultVO;
import top.tangyh.lamp.care.vo.query.BGenItemDetailPageQuery;

import java.util.List;

/**
 * <p>
 * 业务实现类
 * 通用项目配置明细表
 * </p>
 *
 * @author zqb
 * @date 2024-07-17 17:16:35
 * @create [2024-07-17 17:16:35] [zqb] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class BGenItemDetailServiceImpl extends SuperServiceImpl<BGenItemDetailManager, Long, BGenItemDetail> implements BGenItemDetailService {

    private final BGenItemDetailMapper bGenItemDetailMapper;

    private final BGenItemMapper bGenItemMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteByParentId(Long id) {
        bGenItemDetailMapper.deleteByParentId(id);
    }

    @Override
    public List<BGenItemDetail> getByParentIds(List<Long> ids) {
        return bGenItemDetailMapper.getByParentIds(ids);
    }

    @Override
    public List<BGenItemDetail> queryDetail(GenItemDetailQueryParam param) {
        return bGenItemDetailMapper.queryDetail(param);
    }


    @Override
    public List<GenItemDetailMapDto> queryAll(GenItemDetailQueryParam param) {
        List<GenItemDetailMapDto> list = bGenItemDetailMapper.queryAll(param);
        return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void quickcreate(GenItemDetailQuickSaveParam param) {
        List<BGenItem> p = bGenItemMapper.selectSysListByCodeAndModel(param.getCode(),param.getModelCode());
        if(CollectionUtil.isEmpty(p)){
            throw new BizException("通用配置项不存在");
        }
        BGenItem item = p.get(0);
        BGenItemDetail yxGenItemDetail = new BGenItemDetail();
        yxGenItemDetail.setGenId(item.getId());
        yxGenItemDetail.setItemName(param.getItemName());
        bGenItemDetailMapper.insert(yxGenItemDetail);
    }
}


